package Servelt;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

public class DisplayDBServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        Connection conn = null;   Statement statement=null;   ResultSet rs;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("加载驱动成功！");

            conn= DriverManager.getConnection("jdbc:mysql://localhost:3307/xiangmu?characterEncoding=utf8","root","1234");
            statement=conn.createStatement();
            String sql="select * from vip";
            rs= statement.executeQuery(sql);

            while (rs.next())
            {
                response.getWriter().println(rs.getString("email")+" "+rs.getString("username")+" "+rs.getString("password")+
                        " "+rs.getString("gender")+" "+rs.getString("telephone")+" "+rs.getString("introduce"));
            }
            rs.close();statement.close();conn.close();
        } catch (Exception e)
        {
            System.out.println(e);
        }
    }
}
